//
// Created by 李传智 on 2018/4/12.
//

#include <jni.h>
#include <android/native_window.h>
#include <android/native_window_jni.h>
#include "IPlayerProxy.h"

extern "C"
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *) {
//JNI_OnLoad(JavaVM *vm) {
    IPlayerProxy::get()->init(vm);
    return JNI_VERSION_1_4;
}

extern "C"
JNIEXPORT void JNICALL
Java_xyz_xgqn_media_VideoView_setRender(JNIEnv *env, jobject, jobject _surface) {
    ANativeWindow *window = ANativeWindow_fromSurface(env, _surface);
    IPlayerProxy::get()->setRender(window);
}

extern "C"
JNIEXPORT void JNICALL
Java_xyz_xgqn_media_VideoView_setDataSource(JNIEnv *env, jobject instance, jstring url_) {
    const char *url = env->GetStringUTFChars(url_, 0);
    IPlayerProxy::get()->setDataSource(url);
    env->ReleaseStringUTFChars(url_, url);
}

extern "C"
JNIEXPORT void JNICALL
Java_xyz_xgqn_media_VideoView_start(JNIEnv *, jobject) {
    IPlayerProxy::get()->start();
}

extern "C"
JNIEXPORT void JNICALL
Java_xyz_xgqn_media_VideoView_pauseOrResume(JNIEnv *, jobject) {
    IPlayerProxy::get()->setPause(!IPlayerProxy::get()->isPaused());
}

extern "C"
JNIEXPORT void JNICALL
Java_xyz_xgqn_media_VideoView_seek(JNIEnv *, jobject, jdouble position) {
    IPlayerProxy::get()->seek(position);
}

extern "C"
JNIEXPORT jdouble JNICALL
Java_xyz_xgqn_media_VideoView_getCurrentPosition(JNIEnv *, jobject) {
    return IPlayerProxy::get()->getCurrentPosition();
}


